package java44th.group.bean.common;



import com.github.pagehelper.PageInfo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**

 * @projectName: project-second
 * @package: java44th.group.bean.common
 * @className: CommonData
 * @author: 杨浩祥
 * @description: TODO
 * @date: 2022/10/12 10:08
 * @version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonData<T> {

    private Integer total;
    private Integer pages;
    private Integer limit;
    private Integer page;
    private List<T> list;


    public static <T> CommonData<T> data(PageInfo<T> pageInfo) {
        int pages = pageInfo.getPages();
        int pageNum = pageInfo.getPageNum();
        int pageSize = pageInfo.getPageSize();
        int total = (int) pageInfo.getTotal();
        List<T> list = pageInfo.getList();
        return new CommonData<T>(total, pages, pageSize, pageNum, list);
    }

    // cwq
    public static <T> CommonData<T> dataWithList (PageInfo pageInfo, List<T> diffList) {
        int pages = pageInfo.getPages();
        int pageNum = pageInfo.getPageNum();
        int pageSize = pageInfo.getPageSize();
        int total = (int) pageInfo.getTotal();
        List<T> list = diffList;
        return new CommonData<T>(total, pages, pageSize, pageNum, list);
    }
}
